package com.innovation.chengzhangriji.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;

import com.innovation.chengzhangriji.R;
import com.innovation.chengzhangriji.ui.widget.CuteButton;
import com.innovation.chengzhangriji.ui.widget.CuteToolbar;

public class ErrorDialogActivity extends BaseActivity implements CuteToolbar.OnClickCuteToolbarListener, View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showAsPopup(this);
        setupLayout();
    }

    private void showAsPopup(Activity activity) {
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        WindowManager.LayoutParams params = activity.getWindow().getAttributes();
        params.width = (int) (288 * dm.density);
        params.height = (int) (312 * dm.density);
        params.alpha = 1.0f;
        params.dimAmount = 0.6f;
        activity.getWindow().setAttributes(params);
    }

    private void setupLayout() {
        setContentView(R.layout.activity_error_dialog);
        CuteToolbar toolbar = (CuteToolbar) findViewById(R.id.toolbar);
        toolbar.setOnClickCuteToolbarListener(this);
        CuteButton button = (CuteButton) findViewById(R.id.button_login);
        button.setOnClickListener(this);
    }

    @Override
    public void onClickLeft() {
        finish();
    }

    @Override
    public void onClickRight() {

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.button_login) {
            setResult(Activity.RESULT_OK);
            finish();
        }
    }
}
